% parameters
% Constant timestepping: grid S doubled for each run, timestep doubled.
% Fully Implicit and Crank-Nicolson timestepping
% cases: best long; and worst long

rows = 5; % # times the program will be runned
T = 0.25; step0 = 25;
r = 0.04; sigmaMax = 0.45; sigmaMin = 0.3; S0 = 100; K1 = 95;
K2 = 105;
nodeM = 1:rows; tol = 10^-6;
% Time Step
steps = step0*2.^(0:rows-1);
V = zeros(rows,1);
nNode = zeros(rows,1);
nIter = zeros(rows,1);

tic
% best case
% Fully Implicit
for i=1:rows
    [V(i), optionV, nIter(i)] = butterflyUnVol(r, sigmaMin,sigmaMax, S0, K1, K2, T,steps(i),0, 'b', tol, i);
    nNode(i) = length(optionV);
end
toc
change = [0;diff(V)];
ratio = [0;0;change(2:end-1)./change(3:end)];
OutputBImplicit = [nNode,steps',nIter,V,change,ratio];
% CN
tic
for i=1:rows
    [V(i), optionV, nIter(i)] = butterflyUnVol(r, sigmaMin,sigmaMax, S0, K1, K2, T,steps(i),1, 'b', tol, i);
    nNode(i) = length(optionV);
end
toc
change = [0;diff(V)];
ratio = [0;0;change(2:end-1)./change(3:end)];
OutputBCN = [nNode,steps',nIter,V,change,ratio];

% worst case
% Fully Implicit
figure
tic
for i=1:rows
    [V(i), optionV, nIter(i)] = butterflyUnVol(r, sigmaMin,sigmaMax, S0, K1, K2, T,steps(i),0, 'w', tol, i);
    nNode(i) = length(optionV);
end
toc
change = [0;diff(V)];
ratio = [0;0;change(2:end-1)./change(3:end)];
OutputWImplicit = [nNode,steps',nIter,V,change,ratio];
figure
% C-N
tic
for i=1:rows
    [V(i), optionV, nIter(i)] = butterflyUnVol(r, sigmaMin,sigmaMax, S0, K1, K2, T,steps(i),1, 'w', tol, i);
    nNode(i) = length(optionV);
end
toc
change = [0;diff(V)];
ratio = [0;0;change(2:end-1)./change(3:end)];
OutputWCN = [nNode,steps',nIter,V,change,ratio];
toc









